import {Component, OnInit} from '@angular/core';
import {Page} from '../../../public/util/page';
import {SettingUrl} from '../../../public/setting/setting_url';
import {States} from '../../../public/setting/enums';
import {Util} from '../../../public/util/util';
import {FinanceService} from '../finance.service';

@Component({
  selector: 'app-active-record',
  templateUrl: './active-record.component.html',
  styleUrls: ['./active-record.component.css']
})
export class ActiveRecordComponent implements OnInit {
  public searchParams: any = {};//搜索参数
  public activeRecordList: Page = new Page(); //供应商
  public _loading: boolean = false;
  public routerLinks = SettingUrl.ROUTERLINK;//路由
  public states = States;       // 状态

  constructor(public financeService: FinanceService) {
  }

  ngOnInit() {
    this.getActiveRecordList();
  }

  /**
   * 查询jlbOreLog列表
   * @param curPage 当前页
   */
  getActiveRecordList(curPage?: number) {
    this._loading = true;
    if (curPage) this.activeRecordList.curPage = curPage;//当有页码时，查询该页数据
    this.activeRecordList.params = {
      createTimeBegin: this.searchParams.createTimeBegin,
      createTimeEnd: this.searchParams.createTimeEnd,
      account: this.searchParams.account,
      curPage: this.activeRecordList.curPage, //目标页码
      pageSize: this.activeRecordList.pageSize, //每页条数
    };
    this.financeService.getActiveRecordList(this.activeRecordList.params).then((res: Page) => {
      this._loading = false;
      this.activeRecordList = res;
    }).catch(err => {
      this._loading = false;
    });
  }

  dateChange(date) {
    if (date && date.length === 2) {
      this.searchParams.createTimeBegin = Util.formateGBdate(date[0]);
      this.searchParams.createTimeEnd = Util.formateGBdate(date[1]);
    } else {
      this.searchParams.createTimeBegin = null;
      this.searchParams.createTimeEnd = null;
    }
  }

  /**
   * 重置搜索
   */
  resetSearch() {
    this.searchParams = {};
    this.getActiveRecordList(1);
  }
}

